package org.dreamfly.dreamalarm;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Service;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.KeyEvent;

public class FirendTellActivity extends LightScreenAndUnlockActivity {

	String firendName="";
	Vibrator vibrator;
	
	public static String firendNameKey="firend_name_key";
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		firendName=this.getIntent().getStringExtra(firendNameKey);
		initFrame();
		vibrator();
	}
	
	private void initFrame(){
		Builder builder=new AlertDialog.Builder(FirendTellActivity.this);
		builder.setMessage(firendName+" tell you that you get up late! Get up!");
		builder.setPositiveButton(R.string.firendtellactivity_dialog_button,
				new DialogInterface.OnClickListener(){  
			public void onClick(DialogInterface dialoginterface, int i){ 
				endActivity();
            }
		});
		builder.show();
	}
	
	private void vibrator(){
		//震动
	    vibrator = (Vibrator) getSystemService(Service.VIBRATOR_SERVICE);
	    long[] pattern = {800, 200, 800, 200};
	    vibrator.vibrate(pattern, 2);  
	}

	@Override 
	public boolean onKeyDown(int keyCode, KeyEvent event) { 
	    // BACK key    
	    if (keyCode == KeyEvent.KEYCODE_BACK) {
	    	endActivity();
	    	return true;
	    }
	    return super.onKeyDown(keyCode, event);
	}
	
	private void endActivity(){
		vibrator.cancel();
		FirendTellActivity.this.finish();
	}
}
